/**
 *
 */
package com.zhuoyue.zhtj.service;

import java.util.List;

import com.eit.eitsite.common.utils.IdGen;
import com.zhuoyue.zhtj.dao.WxxxDao;
import com.zhuoyue.zhtj.entity.Wxxx;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.eit.eitsite.common.persistence.Page;
import com.eit.eitsite.common.service.CrudService;
import com.zhuoyue.zhtj.entity.Tyxx;
import com.zhuoyue.zhtj.dao.TyxxDao;

/**
 * 基本信息Service
 * @author hss
 * @version 2017-08-15
 */
@Service
@Transactional(readOnly = true)
public class TyxxService extends CrudService<TyxxDao, Tyxx> {
	@Autowired
	private TyxxDao tyxxDao;
	@Autowired
	private WxxxDao wxxxDao;

	public Tyxx get(String id) {
		return super.get(id);
	}
	
	public List<Tyxx> findList(Tyxx tyxx) {
		return super.findList(tyxx);
	}
	
	public Page<Tyxx> findPage(Page<Tyxx> page, Tyxx tyxx) {
		return super.findPage(page, tyxx);
	}
	
	@Transactional(readOnly = false)
	public void save(Tyxx tyxx) {
		super.save(tyxx);
	}
	
	@Transactional(readOnly = false)
	public void delete(Tyxx tyxx) {
		super.delete(tyxx);
	}

	public boolean checkInfo(Tyxx tyxx){
		Tyxx prinical= tyxxDao.checkInfo(tyxx);
		if(prinical!=null){
			return true;
		}
		return false;
	}

	public String selectNameByXh(Tyxx tyxx){
		Tyxx tyxxs=tyxxDao.selectNameByXh(tyxx);
		if(tyxxs!=null){
			return tyxxs.getXm();
		}
		return null;
	}

	@Transactional
	public boolean register(Tyxx tyxx, Wxxx wxxx){
		//TODO 调用校园系统验证


		if(wxxx.getOpenid()!=null){
			tyxx.setId(IdGen.uuid());
			tyxxDao.insert(tyxx);
			wxxx.setId(IdGen.uuid());
			wxxx.setStuid(tyxx.getXh());
			wxxxDao.insert(wxxx);
			return true;
		}
		return false;
	}
}